﻿using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using wUniApp.MVC.App_GlobalResources;

namespace wUniApp.MVC
{
  // http://stackoverflow.com/questions/1808097/mvc-override-default-validationmessage

  public class wLocDisplayAttribute : DisplayNameAttribute
  {
    public wLocDisplayAttribute(string text)
    {
      try
      {
        DisplayNameValue = Resources.ResourceManager.GetString(text);
      }
      catch
      {
        DisplayNameValue = text;
      }
    }
  }

  public class wLocRequiredAttribute : RequiredAttribute, IClientValidatable
  {
    public wLocRequiredAttribute()
    {
      ErrorMessage = Resources.FieldIsRequired;
    }

    public IEnumerable<ModelClientValidationRule> GetClientValidationRules(ModelMetadata metadata, ControllerContext context)
    {
      yield return new ModelClientValidationRule
      {
        ErrorMessage = this.ErrorMessage,
        ValidationType = "required"
      };
    }
  }
}